package com.lpw.dbvideo.videoorder.dao;

import com.lpw.dbvideo.videoorder.domain.VideoOrder;
import com.lpw.dbvideo.videoorder.provider.VideoOrderProvider;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface VideoOrderMapper {

    /**
     * 新增订单，并返回带主键的数据
     * @param record 新增的数据
     * @return int
     */
    @InsertProvider(type = VideoOrderProvider.class, method = "insert")
    @Options(useGeneratedKeys = true,keyColumn = "id",keyProperty = "id")
    int insert(VideoOrder record);

    /**
     * 通过订单id查询订单
     * @param id 订单id
     * @return VideoOrder
     */
    @Select("select * from video_order where id= #{video_order_id}")
    VideoOrder findById(@Param("video_order_id") int id);

    /**
     * 通过交易单号获取订单对象
     * @param outTradeNo 交易单号
     * @return VideoOrder
     */
    @Select("select * from video_order where out_trade_no = #{out_trade_no}")
    VideoOrder findByOutTradeNo(@Param("out_trade_no") String outTradeNo);

    /**
     * 逻辑删除订单
     * @param id 订单id
     * @param userId 用户id
     * @return int
     */
    @Update("update video_order set del = 0 where id = #{id} and user_id = #{userId}")
    int delUpdate(@Param("id")String id,@Param("userId") String userId);

    /**
     * 查找我的订单列表
     * @param userId 用户id
     * @return List<VideoOrder>
     */
    @Select("select * from video_order where user_id = #{userId}")
    List<VideoOrder> fingMyVideoOrderList(int userId);

    /**
     * 根据订单流水号更新
     * @param videoOrder 更新内容
     * @return int
     */
    @UpdateProvider(type = VideoOrderProvider.class, method = "updateVideoOrderByOutTradeNo")
    int updateVideoOrderByOutTradeNo(VideoOrder videoOrder);
}